import { message, Space, Popconfirm } from 'antd';
import moment from 'moment';
export const tableHead = [
  {
    code: 'stationId',
    name: '场站编码',
    width: 160,
  },
  {
    code: 'stationName',
    name: '场站名称',
    width: 160,
  },
  {
    code: 'unitType',
    name: '机组类型',
    width: 160,
    render: (text) => {
      return !!text ? (
        <div title={text}>{text.length > 15 ? text.slice(0, 15) + '...' : text}</div>
      ) : (
        '-'
      );
    },
  },
  {
    code: 'stationCapacity',
    name: '容量（万kWh）',
    width: 140,
    render: (text) => {
      return !!text ? (text / 10).toFixed(2) : '-';
    },
  },
  {
    code: 'fanCount',
    name: '风机台数',
    width: 120,
  },
  {
    code: 'ratedPower',
    name: '额定功率（kW）',
    width: 140,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'cutoutWindspeed',
    name: '切出风速10分钟m/s',
    width: 140,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'createBy',
    name: '创建人',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'createTime',
    name: '创建时间',
    width: 160,
    render: (text) => {
      return !!text ? moment(text).format('YYYY-MM-DD hh:mm:ss') : '-';
    },
  },
  {
    code: 'updateBy',
    name: '修改人',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'updateTime',
    name: '修改时间',
    width: 160,
    render: (text) => {
      return !!text ? moment(text).format('YYYY-MM-DD hh:mm:ss') : '-';
    },
  },
];
export const tableHead_1 = [
  {
    code: 'unitType',
    name: '机组类型',
    width: 160,
    render: (text) => {
      return !!text ? (
        <div title={text}>{text.length > 15 ? text.slice(0, 15) + '...' : text}</div>
      ) : (
        '-'
      );
    },
  },
  {
    code: 'ratedPower',
    name: '额定功率（kW）',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'cutoutWindspeed',
    name: '切出风速10分钟m/s',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'createBy',
    name: '创建人',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'createTime',
    name: '创建时间',
    width: 160,
    render: (text) => {
      return !!text ? moment(text).format('YYYY-MM-DD hh:mm:ss') : '-';
    },
  },
  {
    code: 'updateBy',
    name: '修改人',
    width: 120,
    render: (text) => {
      return text || '-';
    },
  },
  {
    code: 'updateTime',
    name: '修改时间',
    width: 160,
    render: (text) => {
      return !!text ? moment(text).format('YYYY-MM-DD hh:mm:ss') : '-';
    },
  },
];
// 判断该用户是否有权限
export const havePermissions = (buttonType, buttonPermissions) => {
  const hasSave = buttonPermissions?.filter((item) => item.menuCode === buttonType)?.length > 0;
  if (!hasSave) {
    message.info('请联系管理员获取相关权限');
    return false;
  } else {
    return true;
  }
};
export const getColumns = (props = {}) => {
  const { type, onChange, buttonPower } = props;
  const columns = type == 'placeType' ? tableHead : tableHead_1;
  return [
    ...columns,
    {
      name: '操作',
      code: 'action',
      fixed: 'right',
      width: 140,
      render: (_, record) => (
        <Space size="middle">
          <a
            onClick={() => onChange?.('edit', record)}
            style={{
              color: !buttonPower['edit'] ? 'var(--font-a30)' : 'var(--font-primary)',
            }}
          >
            编辑
          </a>
          <Popconfirm
            placement={'topRight'}
            title="确认删除？"
            onConfirm={() => onChange?.('delete', record)}
          >
            <a
              style={{
                color: !buttonPower['delete'] ? 'var(--font-a30)' : 'var(--font-primary)',
              }}
            >
              删除
            </a>
          </Popconfirm>
        </Space>
      ),
    },
  ];
};
